// 交叉

interface DogInterface {
  run(): void;
}

interface CatInterface {
  jump(): void;
}

let pet: DogInterface & CatInterface;

// @ts-ignore
class Dog implements DogInterface {
  run() {
  }

  eat() {
  }
}

// @ts-ignore
class Cat implements CatInterface {
  jump() {
  }

  eat() {
  }
}

enum Master { Boy, Girl };

function getPet(master: Master) {
  const pet = master === Master.Boy ? new Dog() : new Cat();
  return pet;
}

console.log(getPet(0));
console.log(getPet(1));


// 联合类型

let a: number | string = 'ataola';
let b: 'a' | 'b' | 'c';
let c: 1 | 2 | 3;


interface Square {
  kind: 'square';
  size: number;
}

interface Rectangle {
  kind: 'rectangle';
  width: number;
  height: number;
}

interface Circle {
  kind: 'circle';
  r: number;
}

type Shape = Square | Rectangle | Circle;

function getArea(shape: Shape) {
  switch (shape.kind) {
    case 'square':
      return shape.size ** 2;
    case 'rectangle':
      return shape.width * shape.height;
    case 'circle':
      return Math.PI * shape.r ** 2;
    default:
      return ((e: never) => {
        throw new Error(e);
      })(shape);
  }
}

console.log(getArea({kind: 'circle', r: 2}));
console.log(getArea({kind: 'square', size: 2}));
console.log(getArea({kind: 'rectangle', width: 2, height: 5}));
